package com.demo.webapp.kcfinder.utils;

import java.io.File;
import java.io.FilenameFilter;
import java.util.HashSet;
import java.util.Set;

import org.apache.commons.io.filefilter.AbstractFileFilter;

/**
 * 文件扩展名过滤器
 * @author ryuu.kk
 *
 */
public class FileExtensionsFilter extends AbstractFileFilter {

	private Set<String> extensionSet;
	
	public FileExtensionsFilter(String...extensions) {
		extensionSet = new HashSet<String>();
		if (extensions != null) {
			for (String e : extensions) {
				extensionSet.add(e.toUpperCase());
			}
		}
	}
	
	@Override
	public boolean accept(File dir, String name) {
		String extension = name.substring(name.lastIndexOf(".") + 1);
		
		return extensionSet.contains(extension.toUpperCase());
	}
	
	public Set<String> getExtensionSet() {
		return this.extensionSet;
	}
	
	public void addExtensions(String exts) {
		extensionSet.add(exts);
	}
}
